package com.atguigu.mpdemo1010.config;

import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

/**
 * @program: mpdemo1010
 * @description:
 * @author: xuejingjing
 * @create: 2020-09-08 06:39
 **/

@Configuration
@MapperScan("com.atguigu.mpdemo1010.mapper") //把所有的配置都放到这个配置类下，不用放到启动类中。
public class Mpconfig {

    /**
     * 乐观锁插件
     * @return
     */
    @Bean
    public OptimisticLockerInterceptor optimisticLockerInterceptor(){
        return  new OptimisticLockerInterceptor();
    }

    /**
     * 分页插件
     * @return
     */
    @Bean
    public PaginationInterceptor paginationInterceptor(){
        return new PaginationInterceptor();
    }

    /**
     * 逻辑删除插件
      * @return
     */

    @Bean
    public ISqlInjector sqlInjector(){
        return  new LogicSqlInjector();
    }


    /**
     * sql 执行性能分析插件
     * 开发环境使用，线上不推荐，maxTime 指的是sql最大执行时长
     * dev   开发环境
     * prod  生产环境
     * test  测试环境
     * @return
     */
    @Bean
    @Profile({"dev","test"})   //设置dev   test环境开启
    public PerformanceInterceptor perfornanceInterceptor(){
        PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
        performanceInterceptor.setMaxTime(100);
        performanceInterceptor.setFormat(true);
        return performanceInterceptor;
    }

}
